package com.itheima.String;

/**
 * @Author 王加鑫
 * @Date 2021/4/27 11:45
 * @Version 1.0
 *
 * ==的四种情况判断
 */
public class StringTest02 {
    public static void main(String[] args) {
        //情况一: 两个引用同时指向同一片常量池中的内存空间
        String s1 = "abc";
        String s2 = "abc";
        System.out.println(s1 == s2);

        //情况二:每次new都是新地址
        String s3 = new String("abc");
        String s4 = new String("abc");
        System.out.println(s3 == s4);

        //情况三:字符串变量 + 常量 等同于new
        String s5 = "ab";
        String s6 = s5 + "c";
        String s7 = new String("abc");
        System.out.println(s6 == s7);
        System.out.println(s6 == s1);

        //情况四:常量优化机制
        String s8 = "a" + "bc";
        String s9 = "ab" + "c";
        System.out.println(s8 == s9);

    }
}
